// 主函数启动服务端
#include <iostream>
#include <memory>
#include "UdpServer.hpp"
#include "Dict.hpp"

using namespace std;

void Usage(string proc)
{
    cout << "Usage:\n\t" << "please input: " << proc << " local_port" << endl;
}

int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERROR);
    }
    // 字典模块
    Dict dict;
    // 网络部分
    uint16_t port = stoi(argv[1]); 
    // make_unique是C++14的语法，这里等效于: 
    // unique_ptr<UdpServer> user(new UdpServer(port, bind(&Dict::Translate, &dict, placeholders::_1))); 
    unique_ptr<UdpServer> usvr = make_unique<UdpServer>(port,
        bind(&Dict::Translate, &dict, placeholders::_1)); 
    usvr->InitServer();
    usvr->Start();
    return 0;
}  
